//
//  CustomNavigationVC.swift
//  SwiftDemo
//
//  Created by 李国卿 on 2020/1/20.
//  Copyright © 2020 guoqing.li. All rights reserved.
//

import UIKit

class CustomNavigationVC: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // 实现全屏 Pop手势实现
        // 1. 获取系统的Pop 手势
        guard let sysytemGes = interactivePopGestureRecognizer else { return }
        // 2. 获取手势 添加的 view
        guard let gesView = sysytemGes.view else { return }
        // 3. 获取target  aciton
        // 3.1 利用运行时机制查询所有属性
        var count: UInt32 = 0
        let ivars = class_copyIvarList(UIGestureRecognizer.self, &count)!
        
        for i in 0..<count {
            let ivar = ivars[Int(i)]
            let name = ivar_getName(ivar)
            print(String(cString: name!))
        }
        
        let targets = sysytemGes.value(forKey: "_targets") as? [NSObject]
        guard let targetObjc = targets?.first else { return }
        print(targetObjc)
        
        // 3.2 取出target
        guard let target = targetObjc.value(forKey:"target") else { return }
        // 3.3 取出action
        let action = Selector(("handleNavigationTransition:"))
        //4 创建手势
        let panGes = UIPanGestureRecognizer()
        gesView.addGestureRecognizer(panGes)
        panGes.addTarget(target, action: action)
        
    }
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //1. 隐藏要 push 的控制器的 tabbar
        viewController.hidesBottomBarWhenPushed = true
        
        super.pushViewController(viewController, animated: animated)
    }
    
    

    
}
